
var config = $.extend(true, {}, listApp, {
    data : {
        service : virtualService,
        searchVm : {
            channelCode : '',
            deviceName:'',
            deviceCode:''
        },
        editVm: {
            editFormRules:{
                formRules:{
                    name : [ {required : true,message : '请输入通道名',trigger : 'change'} ],
                    deviceId : [ {required : true,message : '请选择设备',trigger : 'change'} ],
                    channelCode : [ {required : true,message : '请输入通道号',trigger : 'change'},
                        {
                            validator:function(rule, value, callback){
                                var reg = /^[0-9]\d{0,2}$/;
                                if(reg.test(value)){
                                    if(value =='999')
                                        callback(new Error('请输入0-998'));
                                    else
                                        callback();
                                }else{
                                    callback(new Error('请输入0-998'));
                                }
                            },
                            trigger:'blur'
                        }],
                    dataType:[{required : true,message : '请输入类型',trigger : 'change'} ]
                }
            }
        },
        requestPagePath:'requestPageList',
        deviceList:[],
        switchDataList:[{
            id:1,
            name:"开关量"
        },{
            id:0,
            name:"模拟量"
        }],
    },
    filters:{
        formatSwitch:function (data) {
            return data ==1 ? '开关量':'模拟量'
        }
    },
    methods : {
        init:function () {
            //加载deviceList
            this.loadDevice();
        },
        loadDevice:function () {
            var _this=this;
            deviceService.getDevicesToVisual("/getAllDevice",null,{
                success:function (ret) {
                    _this.deviceList=ret;
                },
                fail:function (res) {
                    _this.showFailMsg(res.msg);
                }
            })
        },
        editFx:function (index,row) {
            window.location.href="/web/virtual/virtualFx?virtualId="+row.id+"&deviceId="+row.deviceId+"&channelCode="+row.channelCode;
            // window.location.href="/web/virtual/test";
        },
        enterChannelCode:function (vm) {
            var reg = /^[0-9]\d{0,2}$/;
            if (reg.test(vm.data.channelCode)) {
                if (vm.data.channelCode != '999'){
                    this.$set(vm.data, 'channelCode',(Array(3).join(0) + vm.data.channelCode).slice(-3));
                }
            }

        },
        addCallback:function () {
            if(this.$refs['editForm']!=null && this.$refs['editForm']!=undefined)
                this.$refs['editForm'].resetFields();
        }
    }
});
var app = new Vue(config);
